home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / OOFILE / Buildable, limited OOFILE / samples / ooftst06.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-27  |  2.0 KB  |  70 lines  |  [TEXT/CWIE]

  1. // Copyright 1994 A.D. Software. All Rights Reserved
  2.  
  3. // OOFTEST6
  4.  
  5. // this sample modifies related data
  6. // including demonstrating the caching of related records
  7. // as would typically be used in a GUI environment
  8.  
  9. // Simple stream I/O is used to interact with the user.
  10. #include "oofile.hpp"
  11.  
  12.  
  13. #include "ooftst02.inc"
  14.  
  15. int main()
  16. {
  17.     cout << "OOFILE Validation Suite - Test 6\n"
  18.          << "Simple test to demonstrate updating related fields" << endl
  19.          << "using the database from ooftst02" << endl;
  20.  
  21.     if (dbConnect::fileExists("ooftst06.db"))
  22.         theDB.openConnection("ooftst06.db");
  23.     else {
  24.         theDB.newConnection("ooftst06.db");
  25.         People.AddTest2Data();
  26.     }
  27.  
  28.     dbView smithVisits(People.Visits); 
  29.     smithVisits << People.Visits->VisitDate() << People.Visits->Why(); 
  30.  
  31.     People.search(People.LastName=="Smith");
  32.     cout << "Dumping Smith and his visits: " << endl 
  33.          << People << endl 
  34.          << smithVisits << endl;
  35.     
  36.     cout << "changing the first reason to 'Computer-Induced Sanity' " << endl;
  37.     People.Visits.gotoRelativeRecord(0);
  38.     People.Visits->Why() = "Computer-Induced Sanity";
  39.     
  40.     cout << "changing the second reason to 'Funny Views' " << endl;
  41.     smithVisits.source()->gotoRelativeRecord(1);  // test navigating via the view
  42.     smithVisits.field(1) = "Funny Views";
  43.  
  44.     People.saveRecord();  // save both changes
  45.  
  46.     cout << "Dumping Smith and changed visits: " << endl 
  47.          << People << endl 
  48.          << smithVisits << endl;
  49.  
  50.     People.AddVisit("14/2/1995", "Anxiety Attacks");
  51.     
  52. // now change to another related record - our new one should be cached
  53.     smithVisits.source()->gotoRelativeRecord(1);  
  54.     smithVisits.field(1) = "Changed Again";
  55.  
  56. // return to the new record (in the cache) and update it    
  57.     smithVisits.source()->gotoRelativeRecord(2);  
  58.     smithVisits.field(0) = "15/2/1994";
  59.     
  60.     People.saveRecord(); 
  61.     cout << "Dumping Smith and visits with added visit: " << endl 
  62.          << People << endl 
  63.          << smithVisits << endl;
  64.          
  65.     cout << "Now dumping the entire Visits file: " << endl << Visits;
  66.     
  67.     cout << "done" << endl;
  68.  
  69.     return EXIT_SUCCESS;
  70. }